﻿using GPS.MODELS;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using GPS.DataAccessLayer;
using AutoMapper;
using PagedList;
using GPS.ENTITYS;
using GPS.COMMON;
using System.IO;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using Oracle.ManagedDataAccess.Client;
using System.Data;
using Microsoft.AspNet.Identity;
using GPS.GPS_DAL;


namespace GPS.Controllers.GSP_Tracking
{
    public class GPS_TrackingCSDTHetHanController : Controller
    {
        DbContextHelper<GPS_NVContext> _db = Singleton<DbContextHelper<GPS_NVContext>>.Inst;
        public ApplicationUser getCurrentUser()
        {
            ApplicationDbContext dbUser = new ApplicationDbContext();

            string userId = User.Identity.GetUserId();

            ApplicationUser _currentUser = dbUser.Users.Find(userId);

            return _currentUser;
        }

        public ActionResult Index(ViewModelDCSDT_HETHAN_GIAYPHEP SearchModel)
        {
            SearchModel.CB_CSDT_DVGTVT_MA = this.getCurrentUser().MA_TINHTP;
            initialCategorySearchAction(SearchModel);

            var entities = Singleton<GPS_CanhBaoDAO>.Inst.GPS_CANHBAO_CSDT(SearchModel.CB_CSDT_DVGTVT_MA);

            var model = new List<ViewModelDCSDT_HETHAN_GIAYPHEP>();

            foreach (var currentEntity in entities)
            {
                model.Add(Mapper.Map<ViewModelDCSDT_HETHAN_GIAYPHEP>(currentEntity));
            }

            var pageIndex = SearchModel.Page ?? 1;
            SearchModel.SearchResults = model.ToPagedList(pageIndex, GPS.COMMON.Constants.PageSize);

            ViewBag.TotalRow = entities.Count();

            return View(SearchModel);
        }

        public void initialCategorySearchAction(ViewModelDCSDT_HETHAN_GIAYPHEP viewModel)
        {
            // ApplicationUser curUser = getCurrentUser();

            ViewBag.DVGTVT_MAs = new SelectList(_db.Filter<SDONVIGTVT>(o => o.DVGTVT_MA == viewModel.CB_CSDT_DVGTVT_MA), "DVGTVT_MA", "DVGTVT_TEN");
            ViewBag.DEFAULT_VALUE_DDL = CategoryCommon.DEFAULT_VALUE_DDL;

           
        }


	}
}